import React, { useState } from "react";
import { Input, Toast } from "antd-mobile";
import ajax from "../axios";
const Nav = (props) => {
  const { setInputShow, InputRef, id, url, back } = props;
  const [value, setValue] = useState("");
  return (
    <div
      className="input_fix"
      onClick={(e) => {
        const myclass = e.target.className;
        if (myclass == "input_fix") {
          setInputShow(false);
        }
      }}
    >
      <div className="input_box">
        <Input
          placeholder="请输入内容"
          value={value}
          ref={InputRef}
          onChange={(val) => {
            setValue(val);
          }}
        />
        <div
          onClick={() => {
            const value1 = value.trim();
            if (!value1) {
              Toast.show({
                position: "top",
                content: "输入不能为空",
              });
              return false;
            }
            ajax("post", url + "?id=" + id + "&content=" + value1).then(
              (res) => {
                setInputShow(false);
                back && back(res.body);
              }
            );
          }}
          className="input_box_ok"
        >
          {"发送"}
        </div>
      </div>
    </div>
  );
};
export default Nav;
